hook::add message bot:vcard 92
set opt(vcard) 1
proc bot:vcard {from type body} {
	if {[cmd [string tolower "$body"] vcard]} {
		if {[string length $body] > 5} {
			set fm "[string range $body 6 [string length $body]]"
			set frm "[user_from_jid $from]/$fm"
			putlog "INFO: vcard $fm by $from"
		} else {
			set frm "$from"
			set fm "you"
			putlog "INFO: vcard by $from"
		}
	   
		set data [createtag vCard -vars [list xmlns "vcard-temp"]]
		set rtime [clock clicks -milliseconds]
		jlib::send_iq "get" "$data" -to "$frm" -command "vcard:reply {$from} $type {$body} {$fm}"
		return stop
	}
}

proc createtag {tagname args} {

	set isempty 1
	set vars    ""
	set chdata  ""
	set subtags ""

	foreach {attr val} $args {
		switch -- $attr {
			-empty   {set isempty $val}
			-vars    {set vars $val}
			-chdata  {set chdata $chdata$val}
			-subtags {set subtags $val}
		}
	}

	set retext [list $tagname $vars $isempty $chdata]
	foreach a $subtags {lappend retext $a}

	return $retext
}
